{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "mydf1 = pd.read_csv('mycl.csv')\n",
    "display(mydf1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.loc[mydf1['水果名']=='苹果']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#mydf1.loc[mydf1['数量']==101]\n",
    "mydf1.loc[mydf1['月份']==202106]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "data = {  \"编号\":[100001,100012,100003,100004],\n",
    "          \"日期\":pd.date_range('20211108', periods=4),\n",
    "          \"姓名\":[\"赵佳\",\"张可\",\"周远\",\"徐南\"],\n",
    "          \"性别\":['女','男','女','男'],\n",
    "          \"年龄\":[25,28,21,30],\n",
    "          \"工资\":[5869.32,7256.34,6895.89,7289.72]\n",
    "       }\n",
    "mydf1 = pd.DataFrame(data) \n",
    "display(mydf1)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.loc[mydf1['性别']!='男']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.loc[mydf1['工资']!=7256.34]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "mydf = pd.read_csv('mycl.csv')\n",
    "#mydf.loc[mydf['数量']>650]\n",
    "mydf['数量']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#mydf.loc[(mydf['水果名']=='苹果') & (mydf['金额']<800)]\n",
    "mydf.loc[(mydf['水果名'] !='苹果') & (mydf['金额']>600) ]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.loc[mydf1['金额']>=1720]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "mydf1 = pd.read_excel('myexcel1.xls',sheet_name=1)\n",
    "display(mydf1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.query(\"城市 == '上海'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.query(\"城市 == '上海' & 数量 >600\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.query(\"业务员 in ['李可','张平'] & 时间 in ['春季','秋季']\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.query(\"数量 in [541,641,721,841]\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mya = 721\n",
    "mydf1.query(\"数量 > @mya\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>编号</th>\n",
       "      <th>日期</th>\n",
       "      <th>性别</th>\n",
       "      <th>工龄</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>姓名</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>赵可佳</th>\n",
       "      <td>100001</td>\n",
       "      <td>2021-12-18</td>\n",
       "      <td>女</td>\n",
       "      <td>5</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>张可</th>\n",
       "      <td>100012</td>\n",
       "      <td>2021-12-19</td>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>周可</th>\n",
       "      <td>100003</td>\n",
       "      <td>2021-12-20</td>\n",
       "      <td>女</td>\n",
       "      <td>4</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>徐南</th>\n",
       "      <td>100004</td>\n",
       "      <td>2021-12-21</td>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         编号         日期 性别  工龄       工资\n",
       "姓名                                    \n",
       "赵可佳  100001 2021-12-18  女   5  5869.32\n",
       "张可   100012 2021-12-19  男   8  7256.34\n",
       "周可   100003 2021-12-20  女   4  6895.89\n",
       "徐南   100004 2021-12-21  男   3  7289.72"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "data = {  \"编号\":[100001,100012,100003,100004],\n",
    "          \"日期\":pd.date_range('20211218', periods=4),\n",
    "          \"姓名\":[\"赵可佳\",\"张可\",\"周可\",\"徐南\"],\n",
    "          \"性别\":['女','男','女','男'],\n",
    "          \"工龄\":[5,8,4,3],\n",
    "          \"工资\":[5869.32,7256.34,6895.89,7289.72]\n",
    "       }\n",
    "mydf1 = pd.DataFrame(data) \n",
    "mydf1.set_index(['姓名'],inplace=True)\n",
    "display(mydf1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>工资</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>姓名</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>赵可佳</th>\n",
       "      <td>2021-12-18</td>\n",
       "      <td>5869.32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>张可</th>\n",
       "      <td>2021-12-19</td>\n",
       "      <td>7256.34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>周可</th>\n",
       "      <td>2021-12-20</td>\n",
       "      <td>6895.89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>徐南</th>\n",
       "      <td>2021-12-21</td>\n",
       "      <td>7289.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            日期       工资\n",
       "姓名                     \n",
       "赵可佳 2021-12-18  5869.32\n",
       "张可  2021-12-19  7256.34\n",
       "周可  2021-12-20  6895.89\n",
       "徐南  2021-12-21  7289.72"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mydf1.filter(items=['日期','工资'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.filter(items=['张可','周可'],axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.filter(like='工')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.filter(like='可',axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.filter(regex='资$',axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mydf1.filter(regex='可$')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
